<template>
  <el-container class="layout-container">
    <el-container>
      <!-- 顶部标题栏 -->
      <el-header class="system-header">
        <div class="brand-logo">
          <img src="@/assets/images/brand-CHN.png" alt="生鲜供应链管理系统" />
        </div>
        
        <!-- 用户信息和退出 -->
        <div class="user-info">
          <el-dropdown @command="handleCommand" placement="bottom-end">
            <span class="user-dropdown-link">
              {{ userStore.user?.username || '用户' }}
              <el-icon><ArrowDown /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="profile" disabled>个人中心</el-dropdown-item>
                <el-dropdown-item command="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      
      <!-- 主内容区域 -->
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'
import { ElMessage } from 'element-plus'
import { ArrowDown } from '@element-plus/icons-vue'

const router = useRouter()
const userStore = useUserStore()

// 处理下拉菜单命令
async function handleCommand(command) {
  if (command === 'logout') {
    await userStore.logout()
    ElMessage.success('已退出登录')
    router.push('/login')
  }
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
}

.system-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.brand-logo {
  height: 100%;
  display: flex;
  align-items: center;
}

.brand-logo img {
  height: 50px;  /* 增加图片高度 */
  width: auto;   /* 保持宽度自适应以维持比例 */
  object-fit: contain;
}

.user-info {
  display: flex;
  align-items: center;
}

.user-dropdown-link {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: #333;
}

.el-main {
  padding: var(--spacing-lg);
  background-color: #f5f7fa;
}
</style> 